
const MinStack=function(){
    this.stack1=[]
    this.stack2=[]
}
MinStack.prototype.push=function(x){
this.stack1.push(x)
// 查找存在的最小值
if (this.stack2.length==0||this.stack2[this.stack2.length-1]>=x) {
    this.stack2.push(x)
}
}
MinStack.prototype.pop=function(){
    if(this.stack1.pop()==this.stack2[this.stack2.length-1]){
        this.stack2.pop()
    }
}
// 
MinStack.prototype.top=function(){
    return this.stack1[this.stack1.length-1]
}
MinStack.prototype.getMin=function(){
    return this.stack2[this.stack2.length-1]
}

const minStack = new MinStack();
minStack.push(3); // 入栈 3
minStack.push(5); // 入栈 5
minStack.push(2); // 入栈 2
minStack.push(1); // 入栈 1
minStack.push(["MinStack","push","push","push","getMin","pop","top","getMin"],
    [[],[-2],[0],[-3],[],[],[],[]]); // 入栈 1

console.log(minStack.getMin()); // 应该输出 1
console.log(minStack.top());     // 应该输出 1
minStack.pop();                  // 弹出 1
console.log(minStack.getMin()); // 应该输出 2
